'use strict';
angular.module('hanxinBroker').directive('checkLessequalSame', function checkLessequalSame() {
  return {
    restrict: 'A',
    require: 'ngModel',
    link: function (scope, element, attrs, ngModel) {
      ngModel.$parsers.push(function (value) {
        if (_.isUndefined(value)) {
          return undefined;
        }
        var anotherValue = scope.$eval(attrs.checkLessequalSame);
        var result = value <= anotherValue;
        ngModel.$setValidity('lessOrEqual', result);

        return result ? value : undefined;
      });
    }
  };
});
